package com.gwz.service.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gwz.mapper.QuartzBeanMapper;
import com.gwz.model.JobBean;
import com.gwz.util.QuartzUtil;
import com.gwz.util.UUIDUtil;


/**
 * quartz任务注册表
 * @author panguixiang
 *
 */
@Service("quartzBeanService")
public class QuartzBeanService {

    @Autowired
    private QuartzBeanMapper quartzBeanMapper;

    public List<JobBean> list() {
        return quartzBeanMapper.list();
    }

    public void addJob(JobBean jobBean) throws Exception {
        jobBean.setId(UUIDUtil.getUUID());
        quartzBeanMapper.add(jobBean);
        QuartzUtil.addJob(jobBean);
    }

    public void remove(String id) throws Exception {
        id = id.trim();
        quartzBeanMapper.remove(id);
        QuartzUtil.deleteJob(id);
    }

    public JobBean getById(String id) throws Exception {
        return quartzBeanMapper.getById(id);
    }

}
